import lombok.SneakyThrows;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author zxs
 * @since 2021/4/21
 */
public class DynamicProxy {

    static interface Interface {
        void doSomething();
    }

    static class InterfaceImpl implements Interface {
        @Override
        public void doSomething() {
            System.out.println("hhhh");
        }
    }

    @SneakyThrows
    public static void main(String[] args) {
        Interface i = new InterfaceImpl();
        Interface proxy = (Interface)Proxy.newProxyInstance(i.getClass().getClassLoader(), new Class[]{Interface.class}, (proxy1, method, args1) -> {
            System.out.println("--------start-------");
            Object result = method.invoke(i, args1);
            System.out.println("--------end-------");
            return result;
        });
        proxy.doSomething();
    }
}
